home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / manchester / 2.2 / ProcessID.st < prev    next >
Text File  |  1993-07-24  |  4KB  |  125 lines

  1. "    NAME        ProcessID
  2.     AUTHOR        rmd@cs.man.ac.uk
  3.     FUNCTION unique id per process 
  4.     ST-VERSIONS    2.2
  5.     PREREQUISITES     
  6.     CONFLICTS    
  7.     DISTRIBUTION      world
  8.     VERSION        1.1
  9.     DATE    22 Jan 1989
  10. SUMMARY    ProcessID
  11.     Generates a unique ID for every process. This ID is
  12.    not dependent on OOP or time, but only on the order in which a process
  13.    forks other processes.(2.2).RMD
  14. "!
  15. 'From Smalltalk-80, Version 2.3 of 13 June 1988 on 5 May 1989 at 2:26:16 pm'!
  16.  
  17.  
  18. [Process addInstVarName: 'processID'] forkAt: Processor highIOPriority!
  19.  
  20. [Process addInstVarName: 'childCount'] forkAt: Processor highIOPriority!
  21.  
  22. Process comment:
  23. 'Class Process represents an independent path of control in the system.  This path of control may be stopped (by sending the instance the message suspend) in such a way that it can later be restarted (by sending the instance the message resume).  When any one of several paths of control can be advanced, the single instance of ProcessorScheduler named Processor determines which one will actually be advanced partly using the instance''s priority.
  24.  
  25. Instance Variables: 
  26.         suspendedContext    <Context> activeContext at time of process suspension
  27.         priority                <Integer> partial indication of relative scheduling
  28.         myList                <LinkedList> on which I am suspended
  29.         processID            <string>    Unique identifier for this process not based on the OOP,                             thereby allowing parallel simulations. This is formed by concatenating                             my parents PID with a count of the number of proeccesses my parent                             has generated.    
  30.         childCount            Count of the number of child processes I have forked - used for                             generating the PID
  31.  
  32. Adding new instance variables is dangerous, do it like this:
  33.  
  34. [Process addInstVarName: ''processID''] forkAt: Processor highIOPriority
  35. '!
  36.  
  37. !Process methodsFor: 'accessing'!
  38.  
  39. nextChildID
  40.     "Return the identifier of my next child. Used as a way of generate unique PIDs"
  41.  
  42. childCount_childCount + 1.
  43. ^processID, '.', (childCount printString)!
  44.  
  45. processID
  46.     "Answer with my unique identifier."
  47.  
  48.     ^processID! !
  49.  
  50. !Process methodsFor: 'printing'!
  51.  
  52. printOn: aStream 
  53.     "Append to the argument aStream a sequence of characters that identifies the receiver."
  54.  
  55.     super printOn: aStream.
  56.     aStream nextPutAll: ' (', self processID, ') in '.
  57.     suspendedContext printOn: aStream! !
  58.  
  59. !Process methodsFor: 'private'!
  60.  
  61. processID: aString 
  62.     "This should never be sent unless you really know what you are doing!! 
  63.      If you do send this, make sure that the ID you assign is unique. 
  64.     When this is set I reset the childCount."
  65.  
  66.     processID _ aString.
  67.     childCount _ 0! !
  68.  
  69. !Process class methodsFor: 'instance creation'!
  70.  
  71. new  
  72.     |newprocess|  
  73.     newprocess_super new.  
  74.     newprocess processID: 'dummy'.  
  75.     ^newprocess! !
  76.  
  77. Process allInstances do: [:each | each processID: 'dummy']!
  78.  
  79. !Process class methodsFor: 'instance creation'!
  80.  
  81. new
  82.     "I am here to make sure that the processID of this new process gets  
  83.     set properly. I could probably be included in forContext:priority:, but  
  84.     since there is nothing to stop a misguided individual using Process new  
  85.     I am here."
  86.  
  87.     "WARNING: This is a real bugger to install or file in, since processes  
  88.     get created all the time, and it is impossible to avoid new ones being  
  89.     generated between intialising all the current ones and accepting this 
  90.      method. Consequently make sure that all the methods used here are  
  91.     defined first, then install the dummy method below, which just sets  
  92.     the process ID (and hence the child count) to a workable value.  
  93.     There by letting things get one.  You must then initilaise all the
  94.     current instances. You can then install the real thing"
  95.  
  96.     "new  
  97.     |newprocess|  
  98.     newprocess_super new.  
  99.     newprocess processID: 'dummy'.  
  100.     ^newprocess"
  101.  
  102.     | newProcess |
  103.     newProcess _ super new.
  104.     newProcess processID: Processor activeProcess nextChildID.
  105.     ^newProcess! !
  106.  
  107. !Process class methodsFor: 'PID initialisation'!
  108.  
  109. initialisePID: aString 
  110.     "Initialise all the currently exisiting processes with unique IDs based  
  111.     on the basename aString, concatenated with a count."
  112.  
  113.     | processList |
  114.     processList _ Process allInstances.
  115.     1 to: processList size do: [:each | (processList at: each)
  116.             processID: aString , '.' , each printString]!
  117.  
  118. initialisePID
  119.     "Initialise all the currently exisiting processes with unique IDs. Prompt 
  120.     for the basenames aString."
  121.     "Process initialisePID"
  122.  
  123.     self initialisePID: (FillInTheBlank request: 'Basename for these processes')! !
  124.  
  125.